package com.zbs.simbot.listener;

import com.zbs.simbot.factory.BasePlugin;
import com.zbs.simbot.config.SimBotConfig;
import com.zbs.simbot.factory.BasePluginFactory;
import com.zbs.simbot.events.BaseMsgEvent;
import lombok.extern.slf4j.Slf4j;
import love.forte.di.annotation.Beans;
import love.forte.simboot.annotation.Listener;
import love.forte.simbot.component.mirai.event.*;
import love.forte.simbot.event.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collection;

@Component
@Slf4j
@Beans
public class BaseListener {

    /**
     * 群消息监听事件
     * @param event
     */
    @Listener
    public void event(GroupMessageEvent event) {
        BaseMsgEvent baseMsgEvent = new BaseMsgEvent(event);
        Collection<BasePlugin> allBasePlugin = BasePluginFactory.getAllBasePlugin();
        allBasePlugin.forEach(plugin -> plugin.defaultRun(baseMsgEvent, plugin));
    }

    /**
     * 好友消息监听事件
     * @param event
     */
    @Listener
    public void event(FriendMessageEvent event) {
        BaseMsgEvent baseMsgEvent = new BaseMsgEvent(event);
        Collection<BasePlugin> allBasePlugin = BasePluginFactory.getAllBasePlugin();
        allBasePlugin.forEach(plugin -> plugin.defaultRun(baseMsgEvent, plugin));
    }

    /**
     * 私聊消息监听事件
     * @param event
     */
    @Listener
    public void event(MiraiMemberMessageEvent event) {
        BaseMsgEvent baseMsgEvent = new BaseMsgEvent(event);
        Collection<BasePlugin> allBasePlugin = BasePluginFactory.getAllBasePlugin();
        allBasePlugin.forEach(plugin -> plugin.defaultRun(baseMsgEvent, plugin));
    }


    /**
     * 好友添加事件
     * @param event
     */
    @Listener
    public void friendAdd(MiraiFriendRequestEvent event) {
        // 是否自动同意加好友
        if (SimBotConfig.autoFriend) {
            log.info("已经自动同意添加好友请求：{}({})",event.getUser().getUsername(),event.getUser().getId());
            event.acceptBlocking();
        }
    }


}
